import '@/styles/main.scss'
import { createApp } from 'vue'
import { createPinia } from 'pinia'
import routes from "@/router/index"
import {useLocalInformationStore} from './stores/LocalInformation'
import {useChatroomStore} from './stores/ChatroomStore'
import { createRouter,createMemoryHistory } from 'vue-router'
import App from './App.vue'
import FingerprintJS from '@fingerprintjs/fingerprintjs'

const router = createRouter({history:createMemoryHistory(),routes})
const app = createApp(App)
router.afterEach((to,from)=>{
    if(to.meta.isContentFlow){
        document.querySelector("#app")?.scroll(0,window.innerHeight)
    }
})
app.use(router)
app.use(createPinia())
app.mount('#app')


const localInfoStore = useLocalInformationStore();
const chatroomStore = useChatroomStore();

let res = await FingerprintJS.load().then(res=>{return res.get()})
const fingerprint = res.visitorId
localInfoStore.$subscribe((mutation,state)=>{
    localStorage.setItem('fingerprint',JSON.stringify(state.fingerprint))
})
localInfoStore.$patch({
    fingerprint: fingerprint,
})
chatroomStore.$subscribe((mutation,state)=>{
    localStorage.setItem("chatroomUser",JSON.stringify(state.chatroomUser))
})

